/*
 * Copyright 2011 Clean GWT
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */
package com.cleangwt.user.client.ui.nojs;

/**
 * @author Jess
 * @version 1.0
 * @since 1.0
 * @deprecated experimatal
 */
public class UIManager {

  // private static Map<Element, HandlerRegistration> dropdownAutoHideRegistrations;
  // private static UIManager instance;
  //
  // public UIManager() {
  // assert instance == null;
  // instance = this;
  // }
  //
  // private void previewDropdownEvent(NativePreviewEvent event) {
  // // If the event has been canceled or consumed, ignore it
  // if (event.isCanceled() || event.isConsumed()) {
  // return;
  // }
  //
  // Event nativeEvent = Event.as(event.getNativeEvent());
  // int type = nativeEvent.getTypeInt();
  //
  // if (type == Event.ONCLICK) {
  // Element element = nativeEvent.getEventTarget().cast();
  // if ((element = getToggleTarget(element, DataModel.TOGGLE_DROPDOWN)) != null) {
  // Element dropdown = element.getParentElement();
  // if (Elements.hasClass(dropdown, Styles.OPEN)) {
  // close(dropdown);
  // } else {
  // open(dropdown);
  // }
  // DOM.eventPreventDefault(nativeEvent);
  // }
  // }
  // }
  //
  // private static Element getToggleTarget(Element e, String toggleType) {
  // if (toggleType.equals(e.getAttribute(DataModel.DATA_TOGGLE))) {
  // return e;
  // } else if(e.getParentElement() != null){
  // Element parent = e.getParentElement();
  // if (toggleType.equals(parent.getAttribute(DataModel.DATA_TOGGLE))) {
  // return parent;
  // }
  // }
  // return null;
  // }
  //
  // private void previewNavbarEvent(NativePreviewEvent event) {
  // // If the event has been canceled or consumed, ignore it
  // if (event.isCanceled() || event.isConsumed()) {
  // return;
  // }
  //
  // Event nativeEvent = Event.as(event.getNativeEvent());
  // int type = nativeEvent.getTypeInt();
  //
  // if (type == Event.ONCLICK) {
  // Element element = nativeEvent.getEventTarget().cast();
  // if ((element = getToggleTarget(element, DataModel.TOGGLE_COLLAPSE)) != null) {
  // Element navbar = element.getParentElement().getParentElement();
  // Element collapse = Elements.getByClass(navbar,
  // Navbar.COLLAPAE_STYLE);
  // if (Elements.hasClass(collapse, Styles.IN)) {
  // collapse.removeClassName(Styles.IN);
  // } else {
  // collapse.addClassName(Styles.IN);
  // }
  // DOM.eventPreventDefault(nativeEvent);
  // }
  // }
  // }
  //
  // /**
  // * Close the menu for the given dropdown.
  // */
  // public void close(Element dropdown) {
  // dropdown.removeClassName(Styles.OPEN);
  // dropdownAutoHideRegistrations.get(dropdown).removeHandler();
  // dropdownAutoHideRegistrations.remove(dropdown);
  // }
  //
  // /**
  // * Opens the menu for the given dropdown.
  // */
  // public void open(final Element dropdown) {
  // dropdown.addClassName(Styles.OPEN);
  // if (dropdownAutoHideRegistrations == null) {
  // dropdownAutoHideRegistrations = new HashMap<Element, HandlerRegistration>();
  // }
  // dropdownAutoHideRegistrations.put(dropdown,
  // Event.addNativePreviewHandler(new NativePreviewHandler() {
  //
  // @Override
  // public void onPreviewNativeEvent(NativePreviewEvent event) {
  // previewAutoHide(dropdown, event);
  // }
  // }));
  // }
  //
  // /**
  // * Preview the {@link NativePreviewEvent} for hiding dropdown menu.
  // *
  // * @param event
  // * the {@link NativePreviewEvent}
  // */
  // private void previewAutoHide(Element dropdown, NativePreviewEvent event) {
  // // If the event has been canceled or consumed, ignore it
  // if (event.isCanceled() || event.isConsumed()) {
  // return;
  // }
  //
  // // If the event targets the dropdown, consume it
  // Event nativeEvent = Event.as(event.getNativeEvent());
  //
  // boolean eventTargetsMenu = eventTargetsDropdown(dropdown, nativeEvent);
  // if (eventTargetsMenu) {
  // int type = nativeEvent.getTypeInt();
  // if (type == Event.ONCLICK) {
  // close(dropdown);
  // event.consume();
  // return;
  // }
  // } else {
  // int type = nativeEvent.getTypeInt();
  // if (type == Event.ONMOUSEDOWN) {
  // close(dropdown);
  // return;
  // }
  // }
  //
  // }
  //
  // private boolean eventTargetsDropdown(Element dropdown, NativeEvent event) {
  // EventTarget target = event.getEventTarget();
  // if (Element.is(target)) {
  // return dropdown.isOrHasChild(Element.as(target));
  // }
  // return false;
  // }
  //
  // @Override
  // public void onModuleLoad() {
  // // drop-down auto binding
  // Event.addNativePreviewHandler(new NativePreviewHandler() {
  //
  // @Override
  // public void onPreviewNativeEvent(NativePreviewEvent event) {
  // previewDropdownEvent(event);
  // }
  // });
  // // nav-bar auto binding
  // Event.addNativePreviewHandler(new NativePreviewHandler() {
  //
  // @Override
  // public void onPreviewNativeEvent(NativePreviewEvent event) {
  // previewNavbarEvent(event);
  // }
  // });
  // }
}
